home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
CLOBJECT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-24
|
11KB
|
349 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: clobject.cpp
// Title: C++ Class Libraries
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains code for the class.
// This code.
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <class.hpp>
//----------------------------------------------------------------------------
// Description: Default constructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M CL_OBJECT::CL_OBJECT()
{
CL_OBJECT::Initialize(CL_INIT_CLASS);
}
//----------------------------------------------------------------------------
// Description: Copy constructor
// Parameters: rccl_object Reference to object to copy.
// Returns:
//----------------------------------------------------------------------------
FN_M CL_OBJECT::CL_OBJECT(RCCL_OBJECT rccl_object)
{
CL_OBJECT::Initialize(CL_INIT_CLASS);
*this = rccl_object;
}
//----------------------------------------------------------------------------
// Description: Destructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M CL_OBJECT::~CL_OBJECT()
{
CL_OBJECT::Destroy(FALSE);
}
//----------------------------------------------------------------------------
// Description: Check an object for an error condition and if set, transfer
// the error condition to the current object.
// Parameters: pcl_object Object to check.
// Returns: IsError().
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::CheckError(PCL_OBJECT pcl_object)
{
if (pcl_object->IsError())
SetError(pcl_object->ErrorCode());
return IsError();
}
//----------------------------------------------------------------------------
// Description: Destroy object. Free any resources used by object.
// Normally called by destructor.
// Should allow multiple calls from various classes.
// Parameters: fDestroyAll Destroy parents also?
// Default is TRUE.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::Destroy(BOOL)
{
CL_OBJECT::Initialize(CL_INIT_CLASS_VARS);
return TRUE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: FALSE.
//----------------------------------------------------------------------------
BOOL FN_MV CL_OBJECT::Error_Debug(PCSZ psz, ...)
{
SetError();
va_list marker;
va_start(marker,psz);
ErrorV_Debug(psz, marker);
va_end(marker);
return FALSE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: FALSE.
//----------------------------------------------------------------------------
BOOL FN_MV CL_OBJECT::ErrorNoMem_Debug(PCSZ pcsz, SIZET cLine)
{
DebugSetLocation((PSZ)pcsz, cLine);
Error_Debug(
"Out of memory.\n"
"Please increase available system memory and try again.");
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Initialize object.
// Normally called by constructor.
// Should allow multiple calls from various classes.
// Parameters: sInit Initialization code. May be one of the following:
// CL_INIT_CLASS Reset class variables and
// and dynamic allocations for
// this class only.
// CL_INIT_CLASS_VARS Reset class variables for
// this class only.
// CL_INIT_VARS Reset class variables.
// CL_INIT_ALL Initialize class and all
// parent class, including
// dynamic memory allocation.
// Default is CL_INIT_ALL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::Initialize(SHORT)
{
errorCode = ERR_SUCCESS;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Assignment operator
// NOTE: Don't copy object into self
// Parameters: rccl_object Reference to right value.
// Returns: Reference to new object.
//----------------------------------------------------------------------------
RCCL_OBJECT FN_M CL_OBJECT::operator=(RCCL_OBJECT rccl_object)
{
if (this != &rccl_object)
{
if (rccl_object.IsError())
{
Destroy();
SetError(rccl_object.ErrorCode());
}
else
{
errorCode = rccl_object.errorCode;
}
}
return (RCCL_OBJECT)*this;
}
//----------------------------------------------------------------------------
// Description: Load an object from persistent storage.
// No error is displayed if the read fails becuase the named
// data was not found!
// Parameters: pcszName Pointer to name of object.
// pcszClass Object class description.
// ppb Pointer to variable to receive address of
// object. Buffer is dynamically allocated and
// must be freed by the caller.
// pcb Pointer to variable to receive size of object.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::ReadObject(PCSZ pcszName, PCSZ pcszClass, PBYTE _FAR_ *ppb, PSIZET pcb)
{
Assert(pcszName && ppb);
if (pcszClass == NULL)
pcszClass = "";
CL_STRING string("%s%s", pcszName, pcszClass);
if (string.IsError())
return FALSE;
if (!CfgFind((PCSZ)string))
return FALSE;
return CfgRead((PCSZ)string, ppb, pcb);
}
//----------------------------------------------------------------------------
// Description: Retrieve object from persistent storage
// Parameters: pcsz Name of object.
// pcszSub Sub-name of object.
// The first character of the name should be '~'.
// If NULL, no sub name is available.
// Default is NULL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::Retrieve(PCSZ pcsz, PCSZ pcszSub)
{
NOTUSED(pcsz);
NOTUSED(pcszSub);
ClearError();
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Store object to persistent storage
// Parameters: pcsz Name of object.
// pcszSub Sub-name of object.
// The first character of the name should be '~'.
// If NULL, no sub name is available.
// Default is NULL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::Store(PCSZ pcsz, PCSZ pcszSub)
{
NOTUSED(pcsz); // Error code is not stored!
NOTUSED(pcszSub);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Save an object to persistent storage.
// Parameters: pcszName Pointer to name of object.
// pcszClass Object class description.
// pb Pointer to object
// cb Size of object.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_OBJECT::WriteObject(PCSZ pcszName, PCSZ pcszClass, PBYTE pb, SIZET cb)
{
Assert(pcszName && pb && cb);
if (pcszClass == NULL)
pcszClass = "";
CL_STRING string("%s%s", pcszName, pcszClass);
if (string.IsError())
return FALSE;
return CfgWrite((PCSZ)string, pb, cb);
}
//----------------------------------------------------------------------------
// Description: Print object value to debugging output.
// Parameters: pccl_object Pointer to dynamic object.
// If NULL, static data elements are printed.
// Default is NULL.
// pcsz Name of object.
// If NULL, no name is displayed.
// Default is NULL.
// cLevel Display level.
// Default is zero.
// Returns:
//----------------------------------------------------------------------------
#if COMPILE_DEBUG
VOID FN_M CL_OBJECT::Print(PCCL_OBJECT pccl_object, PCSZ pcsz, SIZET cLevel)
{
#if COMPILE_TEST
OutputL(cLevel, "CL_OBJECT%s%s", (pcsz?"::":""), (pcsz?pcsz:""));
cLevel++;
if (pccl_object)
{
Output(" <%p>\n", pccl_object);
OutputL(cLevel, "errorCode = %lu\n", (ULONG)pccl_object->errorCode);
if (pccl_object->IsError())
OutputL(cLevel, "Object is in an error state.\n");
if (!pccl_object->IsValid())
OutputL(cLevel, "Object is not valid.\n");
}
else
Output(" <NULL>\n");
return ;
#else
NOTUSED(cLevel);
NOTUSED(pccl_object);
NOTUSED(pcsz);
return ;
#endif
}
#endif
//----------------------------------------------------------------------------
// Description: Run standard test suite on object.
// Parameters: sTest Test to run.
// If 0, run default tests.
// Default is 0.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_DEBUG
BOOL FN_M CL_OBJECT::Test(SHORT sTest)
{
#if COMPILE_TEST
CL_OBJECT obj1, obj2;
if (sTest == 0 || sTest == 1)
{
CL_OBJECT cl_object;
cl_object.Store("CL_OBJECT");
cl_object.Retrieve("CL_OBJECT");
CL_OBJECT::Print(&cl_object);
}
if (sTest == 0 || sTest == 2)
{
obj1.SetError(5);
obj2 = obj1;
CL_OBJECT::Print(&obj2);
}
return TRUE;
#else
NOTUSED(sTest);
return TRUE;
#endif
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------